package com.tuanchau.android.englishtooltip.ui.activity;

import java.io.File;
import java.util.Vector;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageChooseManager extends Activity{

	public void onCreate(Bundle savedInstantState){
		
	}
	
	private class ImageAdapter extends BaseAdapter{
		
		private Context context;
		private Vector<String>pathList;
		
		public ImageAdapter(Context context, Vector<String>pathList){
			this.context = context;
			this.pathList = pathList;
		}
		
		public int getCount() {
			return pathList.size();
		}

		public Object getItem(int position) {
			return pathList.get(position);
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView imageView;
			
			if (convertView == null) {
                imageView = new ImageView(context);
                imageView.setLayoutParams(new GridView.LayoutParams(45, 45));
                imageView.setAdjustViewBounds(false);
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(8, 8, 8, 8);
            } else {
                imageView = (ImageView) convertView;
            }
			
			//imageView.setImageResource(pathList.get(position));
			File imgFile = new File(pathList.get(position));
			if(imgFile.exists()){
				Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
				imageView.setImageBitmap(bitmap);
			}
			
			return imageView;
		}
		
	}
}
